package com.ship.common.core.mybatis.mapping;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 31463
 */
public class MappingContext {

    private static final Map<Class<?>, BaseMapping> MAP = new HashMap<>(16);

    static {
        MAP.put(String.class, new StringMapping());
        MAP.put(Long.class, new EqualMapping());
        MAP.put(BigDecimal.class, new EqualMapping());
        MAP.put(Integer.class, new EqualMapping());
        MAP.put(Boolean.class, new EqualMapping());
        MAP.put(long.class, new EqualMapping());
        MAP.put(int.class, new EqualMapping());
        MAP.put(List.class, new ListMapping());
        MAP.put(Date.class, new EqualMapping());
    }

    private MappingContext() {
    }

    public static BaseMapping getMapping(Class<?> clazz) {
        if (MAP.containsKey(clazz)) {
            return MAP.get(clazz);
        }
        for (Map.Entry<Class<?>, BaseMapping> entry : MAP.entrySet()) {
            Class<?> aClass = entry.getKey();
            if (clazz.isAssignableFrom(aClass)) {
                return MAP.get(aClass);
            }
        }
        return null;
    }
}
